import { Row, Col, Switch, Tag, DatePicker, Tabs, Icon, Form, Input, TimePicker, Button, Modal } from 'antd';
import { WeaQrcode, WeaDialog, WeaBrowser, WeaNewScroll, WeaRichText, WeaAvatar } from 'ecCom';
import isEmpty from 'lodash/isEmpty';
import Collapse from "../../collapse.js"
let _this = null;
const confirm = Modal.confirm;


import { inject, observer } from 'mobx-react';
import { observable, action, toJS } from 'mobx';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
@inject('meetingDialog')
class TabDiscuss extends React.Component {
	constructor(props) {
		super(props);
		_this = this;
		this.state = {
			// title: props.title ? props.title : '请输入标题',
			BrowserList: {
				'create': {
					remark: ''
				},
				datas: [],
			},
		}
	}
	shouldComponentUpdate(nextProps, nextState) {
		//组件渲染控制
		//return this.props.title !== nextProps.title
		return true;
	}
	componentDidMount() {
		let { dialogStatus } = this.props.meetingDialog;
		let { exchangeList } = toJS(dialogStatus);
		let BrowserList = {};
		exchangeList.datas.forEach((element, index) => {
			if (BrowserList[element['id']] == undefined) {
				BrowserList[element['id']] = {};
			}
			BrowserList[element['id']].remark = element.remark
			BrowserList[element['id']].docids = element.docids
			BrowserList[element['id']].projectids = element.projectids
			BrowserList[element['id']].relatedcus = element.relatedcus
			BrowserList[element['id']].relateddoc = element.relateddoc
			BrowserList[element['id']].relatedprj = element.relatedprj
			BrowserList[element['id']].relatedwf = element.relatedwf
		})
    BrowserList.datas = exchangeList.datas
		this.setState({ BrowserList: BrowserList })

	}
	componentWillReceiveProps(nextProps) {
		let { dialogStatus } = this.props.meetingDialog;
		let { exchangeList } = toJS(dialogStatus);
		let BrowserList = {};
		exchangeList.datas.forEach((element, index) => {
			if (BrowserList[element['id']] == undefined) {
				BrowserList[element['id']] = {};
			}
			BrowserList[element['id']].remark = element.remark
			BrowserList[element['id']].docids = element.docids
			BrowserList[element['id']].projectids = element.projectids
			BrowserList[element['id']].relatedcus = element.relatedcus
			BrowserList[element['id']].relateddoc = element.relateddoc
			BrowserList[element['id']].relatedprj = element.relatedprj
			BrowserList[element['id']].relatedwf = element.relatedwf
		})
		BrowserList.datas = exchangeList.datas
		this.setState({ BrowserList: BrowserList })
	}



	render() {
		let { dialogStatus , oldSecretLevel } = this.props.meetingDialog;
		let { exchangeList,isPro,meetingname } = toJS(dialogStatus);
		const { BrowserList } = this.state;
		const { meetingid } = this.props;
		let exchangeListDatas = exchangeList ? exchangeList.datas : [];
    let bottomBarConfig = [];
    let extentsConfig = [];
		let mirror = {
			Document: { type: 37, name: getLabel(126529,"文档"), icon: 'icon-blog-Document' },
			Flow: { type: 152, name: getLabel(131692,"流程"), icon: 'icon-blog-Process' },
			Customer: { type: 18, name: getLabel(30043,"客户"), icon: 'icon-blog-Personnel' },
			Project: { type: 135, name: getLabel(30046,"项目"), icon: 'icon-blog-Project' },
			Task: { type: 'prjtsk', name: getLabel(383349,"任务"), icon: 'icon-blog-Task' },
		}
		let objDocument = {
			name: 'Browser',
			show: <div className="wea-cb-item">
				<span className={`wea-cbi-icon ${mirror['Document'].icon}`} />
				<span className="wea-cbi-text">{mirror['Document'].name}</span>
			</div>,
			type: mirror['Document'].type,
      title: mirror['Document'].name,
      completeParams:{secretLevel:oldSecretLevel},
      dataParams:{secretLevel:oldSecretLevel}
		};
		let objFlow = {
			name: 'Browser',
			show: <div className="wea-cb-item">
				<span className={`wea-cbi-icon ${mirror['Flow'].icon}`} />
				<span className="wea-cbi-text">{mirror['Flow'].name}</span>
			</div>,
			type: mirror['Flow'].type,
      title: mirror['Flow'].name,
      completeParams:{secretLevel:oldSecretLevel},
      dataParams:{secretLevel:oldSecretLevel}
		};
		let objCustomer = {
			name: 'Browser',
			show: <div className="wea-cb-item">
				<span className={`wea-cbi-icon ${mirror['Customer'].icon}`} />
				<span className="wea-cbi-text">{mirror['Customer'].name}</span>
			</div>,
			type: mirror['Customer'].type,
			title: mirror['Customer'].name,
		};

		let objProject = {
			name: 'Browser',
			show: <div className="wea-cb-item">
				<span className={`wea-cbi-icon ${mirror['Project'].icon}`} />
				<span className="wea-cbi-text">{mirror['Project'].name}</span>
			</div>,
			type: mirror['Project'].type,
			title: mirror['Project'].name,
		};
		let objTask = {
			name: 'Browser',
			show: <div className="wea-cb-item">
				<span className={`wea-cbi-icon ${mirror['Task'].icon}`} />
				<span className="wea-cbi-text">{mirror['Task'].name}</span>
			</div>,
			type: mirror['Task'].type,
			title: mirror['Task'].name,
		};

		exchangeList.docids && bottomBarConfig.push(objDocument);//相关文档
		exchangeList.relatedwf && bottomBarConfig.push(objFlow);//相关流程
		exchangeList.relatedcus && bottomBarConfig.push(objCustomer);//相关客户
		exchangeList.projectids && bottomBarConfig.push(objProject);//相关项目
		exchangeList.relatedprj && bottomBarConfig.push(objTask);//相关任务
		exchangeList.relateddoc && bottomBarConfig.push({
			name: 'Upload',
			show: <div className="wea-cb-item">
				<span className='wea-cbi-icon icon-blog-Enclosure' />
				<span className="wea-cbi-text">{getLabel(128158,"附件")}</span>
			</div>,
			uploadId: 'meeting_edit',
			uploadUrl: `${exchangeList.relateddoc.uploadUrl}${exchangeList.relateddoc.uploadUrl.indexOf("category")<0?("?category="+exchangeList.relateddoc.category):""}`,
			category: exchangeList.relateddoc.category,
      maxUploadSize: exchangeList.relateddoc.maxUploadSize,
      mixUploadSize: exchangeList.relateddoc.mixUploadSize,
			style: { display: "inline-block", padding: 0 }
		})
		//相关附件--relateddoc
		let browserParam = {
			hasAddBtn: false,
			hasAdvanceSerach: true,
			idSeparator: ",",
			isAutoComplete: 1,
			isDetail: 0,
			isMultCheckbox: false,
			isSingle: true,
			linkUrl: "/hrm/resource/HrmResource.jsp?id=",
			pageSize: 10,
			quickSearchName: "",
			title: getLabel(383424,"人力资源"),
			type: "1",
			viewAttr: 1,
    }
		return (
			<div className="preview-tabDiscuss"
				style={{ backgroundColor: '#f7f7f7', padding: '16px 16px 0 16px', height: '100%',overflow: 'auto' }}
			>

				{
					Array.isArray(BrowserList.datas) && BrowserList.datas.map((element, index) => {
            extentsConfig = [{
              name: "At",
              data: exchangeList.atList,
              position:'first',
              pushMessageParams: {
                title: meetingname,
                context: `${exchangeList.userName}：<p>${this.state.BrowserList[element.id].remark}`,
                groupCode: "2103",
                linkurl: `/spa/meeting/static/index.html#/main/meeting/dialogsingle?meetingid=${meetingid}&isDiscuss=1`,
                linkMobileUrl: `/spa/meeting/static4mobile/index.html#/calendar/detail?meetingid=${meetingid}&isDiscuss=1`,
              }
            }];
						let replaceDatas = [];
						replaceDatas.push(element.creater);
						let WeaRichTextValue = element.remark ? element.remark : '';
						let baseParams = {
							'37': 'docids',
							'152': 'relatedwf',
							'18': 'relatedcus',
							'135': 'projectids',
							'prjtsk': 'relatedprj',
						}
						element['id'] == BrowserList[element['id']]
						let newbottomBarConfig = bottomBarConfig.map((_element, _index) => {
							_element['memorise'] = true
							for (let key in BrowserList) {
								if (key == element['id']) {
									return { ..._element, replaceDatas: BrowserList[element['id']][baseParams[_element.type]] }
								}
							}
							return _element
						})
						newbottomBarConfig.push({
							name: 'Component',
							show: <span>
								<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ta5v3f@submit`} key="submit" type="primary" style={{ display: 'inline-block', borderRadius: '3px' }} onClick={() => this.dosubmit(element.id)} ><span className="icon-coms-Release" style={{ paddingRight: '7px' }} />{getLabel(383336,"提交")}</Button>
								<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@6td4qa@cancel`} key="cancel" type="primary" style={{ display: element.id != 'create' ? 'inline-block' : 'none', marginLeft: '5px', borderRadius: '3px' }} onClick={() => { this.docancel(index) }} >{getLabel(31129,"取消")}</Button>
							</span>
						})


						let show = element.isEdit == true ?
							<WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@3xv7yv@forEdit_${index}`} height='276px'>
								<div style={{ backgroundColor: '#ffffff', height: '242px', marginBottom: '10px' }}>
									<WeaRichText ecId={`${this && this.props && this.props.ecId || ''}_WeaRichText@o20usp@forEdit_${index}`}
										id={`${element.id}_discuss`}
										ref={`${element.id}_discuss`}
										value={this.state.BrowserList[element.id].remark}
										ckConfig={{
											toolbar: [
												{ name: 'document', items: ['Source'] },
												{ name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', '-', 'NumberedList', 'BulletedList'] },
												{ name: 'styles', items: ['Format', 'Font', 'FontSize'] },
												{ name: 'colors', items: ['TextColor'] },
												{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike',] },
												{ name: 'insert', items: ['Image', 'Table', 'Smiley'] }
											],
											extraPlugins: 'autogrow',
											height: 150,
											autoGrow_minHeight: 150,
											autoGrow_maxHeight: 160,
											removePlugins: 'resize',
											uploadUrl: '/api/doc/upload/uploadFile?model=reply',
                    }}
										extentsConfig={extentsConfig}
										bottomBarConfig={newbottomBarConfig}
										onChange={(text) => this.onChange(element.id, text)}
										onStatusChange={s => { }}
										onToolsChange={(name, ids, list, type) => this.transfStr(name, ids, list, type, element.id)}
									/>
								</div>
							</WeaNewScroll>
							: <div style={{ borderBottom: '1px solid #E2E2E2', padding: "10px 10px 0 10px", backgroundColor: '#ffffff' }}>
								<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@msgjaz@forView_${index}`} >
									{/*<WeaNewScroll height = "110px">*/}
									<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@tduhof@forView_${index}`} span={2}>
									{
										element.creater&&element.creater.id ? <span style={{height:'40px',width:'40px',borderRadius:'20px',display:'inline-block'}}>
											<WeaAvatar ecId={`${this && this.props && this.props.ecId || ''}_WeaAvatar@rfm7od`} // url加载失败显示默认处理
													userId={element.creater.id}
											/>
										</span>
										:
										<img src={`${element.creater.imgurl}`} style={{ height: '40px', width: '40px', borderRadius: '20px' }} />
									}
									</Col>
									<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@vv7eah@forView_${index}`} span={22}>

										<div style={{ marginBottom: '8px' }}>
											<WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@7fjlw7@forView_${index}`} {...browserParam} replaceDatas={replaceDatas} />
										</div>

										{
											<div className="discuss-remark-content" dangerouslySetInnerHTML={{ __html: element.remark }} style={{ paddingBottom: '10px',overflow: 'auto'}} />
										}
										{
											element.projectids.length > 0 ?
												element.projectids.map((e, _index) => {//相关项目
													return <div>
														<span className="icon-blog-Project" style={{ paddingRight: '5px' }} />
														<a href='javascript:void(0)' linkid={e.id} linkType='workflow'
															onClick={() => openMeetingAppLink('project', e.id, meetingid,isPro)} ondblclick={() => false}
															unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.name} </a>
													</div>
												}) : ''
										}
										{
											element.relatedcus.length > 0 ?
												element.relatedcus.map((e, _index) => {//客户
													return <div>
														<span className="icon-blog-Personnel" style={{ paddingRight: '5px' }} />
														<a href='javascript:void(0)' linkid={e.id} linkType='workflow'
															onClick={() => openMeetingAppLink('crm', e.id, meetingid,isPro)} ondblclick={() => false}
															unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.name} </a>
													</div>
												}) : ''
										}
										{
											element.relateddoc.length > 0 ?
												element.relateddoc.map((e, _index) => {//修改成附件
													if (e.showLoad) {
														return <div>
															<span className="icon-blog-Enclosure" style={{ paddingRight: '5px' }} />
															<a onClick={() => openMeetingDiscussDoc(this, e.fileid, meetingid)} href='javascript:void(0);'
																unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.filename}</a>
															<a unselectable='off' contenteditable='false' href={e.loadlink} target='_blank'
																 style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{`${getLabel(258,"下载")}(${e.filesize})`}</a>
														</div>
													} else {
														return <div>
															<span className="icon-blog-Enclosure" style={{ paddingRight: '5px' }} />
															<a onClick={() => openMeetingDiscussDoc(this, e.fileid, meetingid)} href='javascript:void(0);'
																unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.filename}</a>
														</div>
													}
												}) : ''
										}
										{
											element.relatedprj.length > 0 ?
												element.relatedprj.map((e, _index) => {
													return <div>
														<span className="icon-blog-Task" style={{ paddingRight: '5px' }} />
														<a href='javascript:void(0)' linkid={e.id} linkType='workflow'
															onClick={() => openMeetingAppLink('task', e.id, meetingid,isPro)} ondblclick={() => false}
															unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.name} </a>
													</div>
												}) : ''
										}
										{
											element.relatedwf.length > 0 ?
												element.relatedwf.map((e, _index) => {//流程
													return <div>
														<span className="icon-blog-Process" style={{ paddingRight: '5px' }} />
														<a href='javascript:void(0)' linkid={e.id} linkType='workflow'
															onClick={() => openMeetingAppLink('workflow', e.id, meetingid,isPro)} ondblclick={() => false}
															unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.name} </a>
													</div>
												}) : ''
										}
										{
											element.docids.length > 0 ?
												element.docids.map((e, _index) => {//文档
													return <div>
														<span className="icon-blog-Document" style={{ paddingRight: '5px' }} />
														<a href='javascript:void(0)' linkid={e.id} linkType='workflow'
															onClick={() => openMeetingAppLink('doc', e.id, meetingid,isPro)} ondblclick={() => false}
															unselectable='off' contenteditable='false' style={{ cursor: 'pointer', textDecoration: 'underline !important', marginRight: '8px' }}>{e.name} </a>
													</div>
												}) : ''
										}
									</Col>
									{/*</WeaNewScroll>*/}
								</Row>
								<Row ecId={`${this && this.props && this.props.ecId || ''}_Row@mb7rxv@forTime_${index}`} style={{ margin: '10px 0' }}>
									<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@axxq0c@forTime_${index}`} span={8} offset={2}>
										<span style={{ color: '#999999' }}>
											{element.time}
										</span>
									</Col>
									<Col ecId={`${this && this.props && this.props.ecId || ''}_Col@9psdeu@editBtn_${index}`} span={14}>
										{
											element.canedit ? (
												<span
													className="wea-mbwcbr-item icon-coms-edit"
													style = {{cursor:'pointer',position:'absolute',right:'90px',color: '#b2b2b2'}}
													onClick={() => this.edit(element.id)}
												><span style={{ color: '#666666' }}>&nbsp;{`${getLabel(126036,"编辑")}`}</span></span>
											) : ""
										}
										{
											element.canedit ? (
												<span
													className="wea-mbwcbr-item icon-coms-delete"
													onClick={() => this.delete(element.id)}
													style = {{position:'absolute',right:'20px',cursor:'pointer', color: '#b2b2b2'}}
												><span style={{ color: '#666666' }}>&nbsp;{`${getLabel(131966,"删除")}`}</span></span>
											) : ""
										}
									</Col>
								</Row>
							</div>
						return show
					})
				}
				{
					exchangeListDatas.length == 1 ?
						<div style={{ textAlign: 'center', height: '135px' }}>
							<span className="icon-Meeting-Unhappy" style={{ display: 'inline-block', marginTop: '50px' }}><span style={{ paddingLeft: '5px' }}>{getLabel(383567,"暂无相关交流")}</span></span>

						</div>

						: ''
				}


			</div>
		)
	}


	edit = (_id) => {
		let { dialogStatus, changeDiscussList } = this.props.meetingDialog;
		let { exchangeList } = toJS(dialogStatus);
		let { BrowserList } = this.state;
		let oldBrowserList = { ...BrowserList };
		let arr = [];
		let oldexchangeList = { ...exchangeList }
		oldexchangeList.datas.forEach((element, index) => {
			if (_id == element['id']) {
				element.isEdit = true;
				if (oldBrowserList[_id] == undefined) {
					oldBrowserList[_id] = {};
				}
				oldBrowserList[_id].relatedwf = element.relatedwf;
				oldBrowserList[_id].docids = element.docids;
				oldBrowserList[_id].projectids = element.projectids;
				oldBrowserList[_id].relatedcus = element.relatedcus;
				oldBrowserList[_id].relateddoc = element.relateddoc;
				oldBrowserList[_id].relatedprj = element.relatedprj;
			}
		})
		this.setState({ BrowserList: oldBrowserList })
		changeDiscussList(oldexchangeList)
	}
	onChange = (id, text) => {
		let { BrowserList } = this.state;
		let oldBrowserList = { ...BrowserList };
		if (oldBrowserList[id] == undefined) {
			oldBrowserList[id] = {};
		} else {
			!this.state.toolChange && Object.keys(oldBrowserList[id]).forEach(keys => { // tool-onChange期间不做筛选
				if(oldBrowserList[id][keys] && oldBrowserList[id][keys].length > 0) {
					let temp = [];
					Array.isArray(oldBrowserList[id][keys]) && oldBrowserList[id][keys].forEach(v => {
						if(keys === 'docids' ) {
						 	text.indexOf(`linktype="doc"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'projectids') {
							text.indexOf(`linktype="project"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relatedcus' ) {
							text.indexOf(`linktype="crm"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relatedprj' ) {
							text.indexOf(`linktype="task"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relatedwf') {
							text.indexOf(`linktype="workflow"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relateddoc') {
							let tempIds = [];
							v.id && text.indexOf(`linktype="file"`) > -1 && Array.isArray(v.id) && v.id.forEach(res => {
								if(text.indexOf(`linkid="${res}"`) > -1) {
									tempIds.push(res);
								}
							}); 
							v.id = tempIds;
							temp.push(v);
						}
					});
					oldBrowserList[id][keys] = temp;
				}
			});
		}
		
		oldBrowserList[id]['remark'] = text;
		this.setState({ BrowserList: oldBrowserList })
	}
	delete = (e) => {
		const { meetingid } = this.props;
		let { exchangeDelete } = this.props.meetingDialog;
		
		confirm({
			title : getLabel(131329,"信息确认"),
			content : getLabel(15097,"确定要删除吗？"),
			onOk(){
				exchangeDelete({ id: e, meetingid: meetingid });
			},
			onCancel() {}
	})

	}
	dosubmit = (id) => {

		let { exchangeSave } = this.props.meetingDialog;
		const { BrowserList } = this.state;
		let oldBrowserList = { ...BrowserList }
		const { meetingid } = this.props;
		let params = oldBrowserList[id];
		if(!this.refs[`${id}_discuss`]) return;
		if(this.refs[`${id}_discuss`].wrappedInstance){
			params = {...params,remark: this.refs[`${id}_discuss`].wrappedInstance.getData()}
		}else {
			params = {...params,remark: this.refs[`${id}_discuss`].getData()}
		}
		let mewParams = { ...params }
		let canSubmit = false;
		for (let key in mewParams) {
			if (key != 'id' && key != 'meetingid') {
				if (key == 'remark') {
					if (mewParams[key]) {
						canSubmit = true
					}
				}
			}
		}

		if (params.docids.length == 0) {
			delete mewParams.docids
		}
		if (params.projectids.length == 0) {
			delete mewParams.projectids
		}
		if (params.relatedcus.length == 0) {
			delete mewParams.relatedcus
		}
		if (params.relateddoc.length == 0) {
			delete mewParams.relateddoc
		}
		if (params.relatedprj.length == 0) {
			delete mewParams.relatedprj
		}
		if (params.relatedwf.length == 0) {
			delete mewParams.relatedwf
		}
		if (params.docids.length > 0) {
			let docidsarr = []
			params.docids.forEach((_e, _index) => {
				docidsarr.push(_e['id']);
			})
			mewParams.docids = docidsarr.join(',');
		}
		if (params.projectids.length > 0) {
			let projectidssarr = []
			params.projectids.forEach((_e, _index) => {
				projectidssarr.push(_e['id']);
			})
			mewParams.projectids = projectidssarr.join(',');

		}
		if (params.relatedcus.length > 0) {//客户和任务有问题
			let relatedcusarr = []
			params.relatedcus.forEach((_e, _index) => {
				relatedcusarr.push(_e['id']);
			})
			mewParams.relatedcus = relatedcusarr.join(',');

		}
		if (params.relateddoc.length > 0) {
			let relateddocarr = []
			params.relateddoc.forEach((_e, _index) => {
				_e['id'] ? relateddocarr.push(_e['id']) : relateddocarr.push(_e['fileid']);
			})
			mewParams.relateddoc = relateddocarr.join(',');

		}
		if (params.relatedprj.length > 0) {
			let relatedprjarr = []
			params.relatedprj.forEach((_e, _index) => {
				relatedprjarr.push(_e['id']);
			})
			mewParams.relatedprj = relatedprjarr.join(',');

		}
		if (params.relatedwf.length > 0) {
			let relatedwfarr = []
			params.relatedwf.forEach((_e, _index) => {
				relatedwfarr.push(_e['id']);
			})
			mewParams.relatedwf = relatedwfarr.join(',');

		}
		mewParams['id'] = id == 'create' ? '' : id;
		mewParams['meetingid'] = meetingid;
		let stateBrowserList = { ...BrowserList };
		stateBrowserList['create']['docids'] = []
		stateBrowserList['create']['projectids'] = []
		stateBrowserList['create']['relatedcus'] = []
		stateBrowserList['create']['relateddoc'] = []
		stateBrowserList['create']['relatedprj'] = []
		stateBrowserList['create']['relatedwf'] = []
    stateBrowserList['create']['remark'] = ''
    if(this.refs[`${id}_discuss`]){
      this.refs[`${id}_discuss`].pushAtMessage(()=>{
      })
    }
		if (canSubmit) {
			this.setState({ BrowserList: stateBrowserList })
			exchangeSave(mewParams);
		} else {
			Modal.warning({
				title: getLabel(382056,"警告"),
				content: getLabel(126982,"请填写内容"),
			});
		}


	}
	docancel = (e) => {

		let { dialogStatus, changeDiscussList } = this.props.meetingDialog;
		let { exchangeList } = toJS(dialogStatus);
		let oldexchangeList = { ...exchangeList }
		oldexchangeList.datas.forEach((element, index) => {
			if (e == index) {
				element.isEdit = false;
			}
		})
		changeDiscussList(oldexchangeList)
	}

	transfStr = (name = '', ids = '', list = [], type = '', id = '') => {
		this.setState({ toolChange: true });
		let { BrowserList } = this.state;
		let { meetingid } = this.props;
		let str = '';
		let idsArr = [];
		const mirror = {
			37: "doc",
			prjtsk: "task",
			18: "crm",
			152: "workflow",
			135: "project",
			workplan: "workplan",
			blogTemplate: "blogTemplate"
		}
		const browserType = {
			37: "docids",
			prjtsk: "relatedprj",
			18: "relatedcus",
			152: "relatedwf",
			135: "projectids",//项目
			Upload: "relateddoc",//附件
		}
		
		let oldBrowserList = { ...BrowserList };
		if (oldBrowserList[id] == undefined) {
			oldBrowserList[id] = {};
		}
		//判断所选中的id是否已记录
		let oldIds = [];
		if(name == 'Browser'){
			oldIds = oldBrowserList[id][browserType[type]].map(item =>{
				return item.id
			})
		}
		list.map(item => {
			if (name === 'Browser') {
				if(oldIds.indexOf(item.id) < 0){
					str +=`&nbsp;<a onclick='openMeetingAppLink("${mirror[type]}",${item.id},${meetingid})' target='new'  linkid='${item.id}' linkType='${mirror[type]}'  unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.name || item.showname}</a>&nbsp;`
					idsArr.push(item.id)
				}
			}
			if (name === 'Upload' && type === 'image') {
				str += '&nbsp;<img class="formImgPlay" src="' + item.imgSrc + '" onclick="ecCom.WeaRichText.playImg(this)" data-imgsrc="' + item.imgSrc + '" />&nbsp;'
			}
			if (name === 'Upload' && type === 'file') {
				str += `&nbsp;<a linkid="${item.fileid}" linktype="file" onclick='openMeetingDiscussDoc(this,${item.fileid},${meetingid})' unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.filename}</a>&nbsp;`
			}
		})

		if (name != 'Upload') {
			oldBrowserList[id][browserType[type]] = list;
		} else {
			oldBrowserList[id]['relateddoc'].push({ id: ids })
		}
		this.setState({ BrowserList: oldBrowserList }, () => {
			setTimeout(() => {
				this.setState({toolChange: false});
			}, 0);
		})
		return str
	}
}

  window.openMeetingDiscussDoc = (t, showid, meetingid) => {
    openFullWindowHaveBar(`/spa/document/index2file.jsp?id=${showid}&isOpenFirstAss=1&meetingid=${meetingid}`)
  }

  window.openMeetingAppLink=(linkType, linkid, meetingid,isPro=false)=>{
        if (linkType == "doc")
          window.open(`/spa/document/index.jsp?id=${linkid}&meetingid=${meetingid}`) ;
        else if (linkType == "task")
          window.open(`/spa/prj/index.html#/main/prj/taskCard?taskid=${linkid}`);
        else if (linkType == "crm")
          isPro?window.open(`/CRM/manage/customer/CustomerBaseView.jsp?CustomerID=${linkid}`):window.open(`/spa/crm/static/index.html#/main/crm/customerView?customerId=${linkid}`);
        else if (linkType == "workflow")
          window.open(`/spa/workflow/static4form/index.html#/main/workflow/req?fromModul=meeting&modulResourceId=${meetingid}&requestid=${linkid}`);
        else if (linkType == "project")
          window.open(`/spa/prj/index.html#/main/prj/projectCard?prjid=${linkid}`);
        else
            return '';
    }

export default TabDiscuss


